/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import model.Documento;
import model.Usuario;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 *
 * @author Jefferson
 */
public class HibernateConfig {
    private static SessionFactory sessionFactory;
    
    public HibernateConfig() {}
    
    public Session openSession() {
        if (sessionFactory == null) {
            criaSessionFactory();
        }
        return sessionFactory.openSession();
    }
    
    public void criaSessionFactory() {
        AnnotationConfiguration cfg = new AnnotationConfiguration();
        cfg.addAnnotatedClass(Usuario.class);
        cfg.addAnnotatedClass(Documento.class);
        sessionFactory = cfg.buildSessionFactory();
    }
}